import { PayloadAction, isFulfilled } from "@reduxjs/toolkit";
import { NulResponse } from "../util/Net";

/**
 * Judge if the given action is successfully performed, but exceptions occurred.
 * @param action action given by the redux toolkit
 * @returns if the given action is exception action
 */
function isExceptionAction(action: PayloadAction<NulResponse<null>>): action is PayloadAction<NulResponse<null>> {
  if (isFulfilled(action)) {
    return action.payload.code !== 0;
  }
  else {
    return false;
  }
}

export { isExceptionAction };